/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.ConnectUnit;
import DTO.Deposit_DTO;
import DTO.WithDraw_DTO;
import java.sql.CallableStatement;
import java.sql.Date;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;
import javax.swing.JOptionPane;

/**
 *
 * @author Nguyen Phi Hung
 */
public class WithDraw_BLL {
   ConnectUnit connection;
    
    public WithDraw_BLL(){
        this.connection = DAL.DAL.getDAL();
    }
    /*
     * tra ve fasle neu insert thanh cong 
     * nguoc lai return true
     */
    public boolean Insert(String  procedure,WithDraw_DTO info) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setDate(1,info.getWithdrawingDate());
        cs.setString(2, info.getBookID());
        cs.setString(3, info.getCustomerName());
        cs.setString(4, info.getIDNumber());
        cs.setFloat(5, info.getAmountOfMoney());
        return cs.execute();
    }
    /*
     * kiem tra su ton tai cua khach hang tren he thong
     */
    public boolean KiemTraThongTin_KH(String procedure,String HoTen,String CMND) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1,HoTen);
        cs.setString(2,CMND);
        cs.registerOutParameter(3, java.sql.Types.BOOLEAN);
        cs.execute();
        boolean result=cs.getBoolean(3);
        if(result==true)
            return true;
        else
            return false;
        
    }
    /*
     * kiem tra khach hang co so huu so tiet kiem can rut khong
     */
    public boolean KiemTraMaSoThuocKH(String procedure,String MaSo,String Hoten,String CMND) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaSo);
        cs.setString(2, Hoten);
        cs.setString(3, CMND);
        cs.registerOutParameter(4, java.sql.Types.BOOLEAN);
        cs.execute();
        return cs.getBoolean(4);
        
    }
    /*
     * kiem tra so tien rut
     */
    public boolean KiemTraSoTienRut(String procedure,String MaSo,float SoTienGui) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaSo);
        cs.setFloat(2, SoTienGui);
        cs.registerOutParameter(3, java.sql.Types.BOOLEAN);
        cs.execute();
        return cs.getBoolean(3);
    }
    /*
     * lay so tien goc tu so tiet kiem
     */
    public float SoTienHienTai_STK(String procedure,String MaSo) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaSo);
        cs.registerOutParameter(2, java.sql.Types.FLOAT);
        cs.execute();
        return cs.getFloat(2);
    }
    /*
     * so tien rut toi thieu
     */
    public float SoTienRutToiThieu(String procedure) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.registerOutParameter(1,java.sql.Types.FLOAT);
        cs.execute();
        return cs.getFloat(1);
    }
    /*
     * Kiểm tra mã sổ là sổ tiêt kiệm loại nào?
     * nếu là sổ tiết kiệm không kỳ hạn thì 
     *  số tiền rút có thể nhập vào trong khoảng giá trị cho phép
     * ngược lại nếu là sổ tiết kiệm có kỳ hạn thì số tiền rút được gán sẵn 
     * vào ô số tiền rút
     */
    //lay ky han cua so tiet kiem
    public int KyHan(String procedure,String MaSo) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaSo);
        cs.registerOutParameter(2, java.sql.Types.INTEGER);
        cs.execute();
        return cs.getInt(2);
    }
    /*  
     * lay so ngay da gui tien ke tu khi mo so
     */
    public int SoNgayGuiTien(String procedure,String MaSo,java.sql.Date NgayRut) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.setString(1, MaSo);
        cs.setDate(2, NgayRut);
        cs.registerOutParameter(3, java.sql.Types.INTEGER);
        cs.execute();
        return cs.getInt(3);
    }
    /*
     * so ngay rut toi thieu
     */
    public int SoNgayGuiTienToiThieu(String procedure) throws Exception
    {
        CallableStatement cs=this.connection.GetCallableStatement(procedure);
        cs.registerOutParameter(1, java.sql.Types.INTEGER);
        cs.execute();
        return cs.getInt(1);
    }
    public static void main(String[] str) throws Exception
    {
        WithDraw_BLL withdraw=new WithDraw_BLL();
        WithDraw_DTO info=new WithDraw_DTO();
        info.setBookID("TS00000005");
        info.setCustomerName("Do  Sam");
        info.setIDNumber("1234567890");
        info.setAmountOfMoney(122);
        info.setWithdrawingDate(new Date(2013, 3, 12));
        JOptionPane.showMessageDialog(null,withdraw.SoNgayGuiTienToiThieu("{call SoNgayGuiToiThieu_STK(?)}"));
    }
}
